﻿using System;
using mojoPortal.Web;
using mojoPortal.Web.Framework;

namespace ud_GoogleTranslate
{
    public partial class GoogleTranslateModule : SiteModuleControl
    {
        // FeatureGuid 5cb1a666-3de9-47df-8b52-ec0df2deeacf

        #region OnInit

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            Load += Page_Load;
        }

        #endregion

        private bool UseSimpleLayout;
        private bool ShowToolbar;
        private bool TrackInGoogleAnalytics;
        private string customCssClass;

        protected void Page_Load(object sender, EventArgs e)
        {
            LoadSettings();
            PopulateLabels();
            PopulateControls();
        }

        private void PopulateControls()
        {
            TitleControl.Visible = !RenderInWebPartMode;
            if (ModuleConfiguration != null)
            {
                Title = ModuleConfiguration.ModuleTitle;
                Description = ModuleConfiguration.FeatureName;
            }
            gt1.ShowToolbar = ShowToolbar;
            gt1.TrackInGoogleAnalytics = TrackInGoogleAnalytics;
            gt1.Layout = UseSimpleLayout ? "SIMPLE" : "HORIZONTAL";
        }


        private void PopulateLabels()
        {
            //TitleControl.EditText = "Edit";
        }

        private void LoadSettings()
        {
            UseSimpleLayout = WebUtils.ParseBoolFromHashtable(Settings, "UseSimpleLayout", UseSimpleLayout);
            ShowToolbar = WebUtils.ParseBoolFromHashtable(Settings, "ShowToolbar", ShowToolbar);
            TrackInGoogleAnalytics = WebUtils.ParseBoolFromHashtable(Settings, "TrackInGoogleAnalytics", TrackInGoogleAnalytics);
            if (Settings.ContainsKey("CustomCssClassSetting"))
            {
                customCssClass = Settings["CustomCssClassSetting"].ToString();
            }
            pnlContainer.ModuleId = ModuleId;
            pnlContainer.CssClass += " " + customCssClass;
        }
    }
}
